package com.piece.core.mongo.service;

import com.piece.core.mongo.repository.MongoAuditLogRepository;
import com.piece.core.mongo.entity.MongoAuditLog;
import com.piece.core.framework.support.bootstrap.DataTable;
import com.piece.core.framework.support.bootstrap.QueryTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Transactional
@Service(value = "mongoAuditLogService")
public class MongoAuditLogService {

    @Autowired
    private MongoAuditLogRepository mongoAuditLogRepository;

    public MongoAuditLog insert(MongoAuditLog log) {
        return mongoAuditLogRepository.save(log);
    }

    public MongoAuditLog update(MongoAuditLog log) {
        return mongoAuditLogRepository.saveOrUpdate(log.getLogId(), log);
    }

    public void delete(String logId) {
        MongoAuditLog log = new MongoAuditLog();
        log.setLogId(logId);
        mongoAuditLogRepository.delete(log);
    }

    public void deleteByClientId(String clientId) {
        MongoAuditLog log = new MongoAuditLog();
        log.setClientId(clientId);
        mongoAuditLogRepository.delete(log);
    }

    public void deleteAll() {
        mongoAuditLogRepository.deleteAll();
    }

    public List<MongoAuditLog> findList(QueryTable queryTable) {
        return mongoAuditLogRepository.find(queryTable);
    }

    public DataTable findPage(QueryTable queryTable) {
        return mongoAuditLogRepository.findPage(queryTable);
    }
}